# load package
library(cheddar)
# load data
data(TL84)
Contains properties applicable to the community.
- Must contain one row of data and title column
- M & N units must be present if they are present in the nodes csv
# create vectors for each field in properties
dir.create("TL84")
# create vectors
title = "Tuesday Lake sampled in 1984"
N.units = "m^-3"
M.units = "kg"
lat = 46.21667
long = 89.53333
habitat = "Freshwater pelagic"
# making a data frame with vectors
properties<-data.frame(title, N.units, M.units, lat, long, habitat)
properties
## title N.units M.units lat long
## 1 Tuesday Lake sampled in 1984 m^-3 kg 46.21667 89.53333
## habitat
## 1 Freshwater pelagic
## write csv #row.names=FALSE the column names wouldnt line up
write.csv(properties, file="TL84/properties.csv", row.names=FALSE)
Defines species and associated properties
- Contains one row for every species in the community
- Node column is the only mandatory column
+ M & N represent Mass & Numerical Abundance
# create vectors that we are putting into a data frame
node = TL84$nodes$node
# Cheddar has a really nice function to collapse the community by any of these categories
M = TL84$nodes$M
N = TL84$nodes$N
kingdom = TL84$nodes$kingdom
phylum = TL84$nodes$phylum
class = TL84$nodes$class
order = TL84$nodes$order
family = TL84$nodes$family
genus = TL84$nodes$genus
species = TL84$nodes$species
# making a data frame with vectors
nodes<-data.frame(node,
M, N, kingdom, phylum, class, order, family, genus, species)
head(nodes)
## node M N kingdom phylum
## 1 Nostoc sp. 7.97e-13 2.0e+06 Bacteria Cyanobacteria
## 2 Arthrodesmus sp. 1.52e-12 4.9e+07 Plantae Charophyta
## 3 Asterionella formosa 1.12e-12 5.0e+06 Chromista Ochrophyta
## 4 Cryptomonas sp. 1 2.03e-13 6.4e+07 Chromista Cryptophyta
## 5 Cryptomonas sp. 2 1.51e-12 2.8e+07 Chromista Cryptophyta
## 6 Chroococcus dispersus 2.39e-13 2.0e+07 Bacteria Cyanobacteria
## class order family genus
## 1 Cyanophyceae Nostocales Nostocaceae Nostoc
## 2 Zygnematophyceae Desmidiales Desmidiaceae Arthrodesmus
## 3 Bacillariophyceae Fragilariales Fragilariaceae Asterionella
## 4 Cryptophyceae Cryptomonadales Cryptomonadaceae Cryptomonas
## 5 Cryptophyceae Cryptomonadales Cryptomonadaceae Cryptomonas
## 6 Cyanophyceae Chroococcales Chroococcaceae Chroococcus
## species
## 1
## 2
## 3 formosa
## 4
## 5
## 6 dispersus
##write csv
write.csv(nodes, file="TL84/nodes.csv", row.names=FALSE)
Optional file that defines foodweb (trophic links)
- File contains a row for every resource consumer trophic interaction in the community
- Values in resource & consumer should contain node names
# create trophic.links.csv for cheddar
resource = TL84$trophic.links$resource
consumer = TL84$trophic.links$consumer
trophic.links<-data.frame(resource, consumer)
head(trophic.links)
## resource consumer
## 1 Cryptomonas sp. 1 Ascomorpha eucadis
## 2 Chroococcus dispersus Ascomorpha eucadis
## 3 Unclassified flagellates Ascomorpha eucadis
## 4 Chromulina sp. Ascomorpha eucadis
## 5 Selenastrum minutum Ascomorpha eucadis
## 6 Trachelomonas sp. Ascomorpha eucadis
## write csv
write.csv(trophic.links, file="TL84/trophic.links.csv", row.names=FALSE)
TL84<-LoadCommunity("./TL84", fn='read.csv')
## You can also weight the trophic interaction in this file by adding a new column.
## For example, in the Chesapeakbay dataset there is a biomass.flow column in trophic.links
# load dataset
data(ChesapeakeBay)
# lets take a peak!
head(ChesapeakeBay$trophic.links)
## resource consumer
## 1 Free bacteria in water column Heterotrophic microflagellates
## 2 Phytoplankton Microzooplankton
## 3 Bacteria attached to suspended particles Microzooplankton
## 4 Heterotrophic microflagellates Microzooplankton
## 5 Phytoplankton Zooplankton
## 6 Bacteria attached to suspended particles Zooplankton
## biomass.flow
## 1 88721.0
## 2 31715.0
## 3 870.9
## 4 31638.0
## 5 37149.0
## 6 1685.4
# Plot 1 species
PlotNvM(TL84, col=1, pch=19, highlight.nodes=NULL, show.web=FALSE) # can easily do without cheddar
PlotNvM(TL84, col=1, pch=19, highlight.nodes=NULL, show.web=TRUE)
PlotNvM(TL84, col=1, pch=19, highlight.nodes='Daphnia pulex') # highlight an individual
PlotNvM(TL84, col=1, pch=19, highlight.nodes='Daphnia pulex',
highlight.links=TrophicLinksForNodes(TL84, 'Daphnia pulex')) # highligh an individual & links
# Plot 2 species
PlotNvM(TL84, col=1, pch=19, highlight.nodes=c('Daphnia pulex','Trichocerca cylindrica'))
#creates a vector of colors with length equaling the number of nodes
node.names<-TL84$nodes$node
for (i in 1:length(node.names)){
if(node.names[i]=='Daphnia pulex'){
node.names[i] <- "red"
} else if(node.names[i]=='Trichocerca cylindrica'){
node.names[i] <- "blue"
} else {
node.names[i] <- "darkgrey"
}
}
trophic.links<-TL84$trophic.links
trophic.links$color<-"black"
for (i in 1:nrow(trophic.links)){
if((trophic.links[i,1] =='Daphnia pulex' | trophic.links[i,2] =='Daphnia pulex' )){
trophic.links[i,3] <- "red"
} else if((trophic.links[i,1] =='Trichocerca cylindrica'| trophic.links[i,2] =='Trichocerca cylindrica')){
trophic.links[i,3] <- "blue"
} else {
trophic.links[i,3] <- "grey"
}
}
PlotNvM(TL84,
col=node.names,
link.col=trophic.links$color,
pch=16,
highlight.nodes=NULL
)
# Compare prey-averaged and chain-averaged trophic level
par(mfrow=c(1,2)) # setting up 2 plots
PlotWebByLevel(TL84, ylim=c(1,5.8),level='PreyAveragedTrophicLevel', main='Prey-averaged',col=1, pch=19, highlight.nodes=NULL) # the mean trophic level of the node's resources, using the matrix inversion method of Levine (1980)
PlotWebByLevel(TL84, ylim=c(1,5.8),level='ChainAveragedTrophicLevel', main='Chain-averaged',col=1, pch=19, highlight.nodes=NULL) # 1 plus the average chain length of all paths from each node to a basal species
# Compare the three different x layouts
par(mfrow=c(1,3))
for(x.layout in c('skinny', 'narrow', 'wide'))
{
PlotWebByLevel(TL84, x.layout=x.layout, main=x.layout, col=1, pch=19, highlight.nodes=NULL)
}
# Compare the effect of staggering levels
par(mfrow=c(1,2))
# No staggering - stagger and max.nodes.per.row are ignored
PlotWebByLevel(TL84, y.layout='compress',col=1, pch=19)
# Stagger
PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19,
max.nodes.per.row=20)
# Highlight pulex
PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19,highlight.nodes='Daphnia pulex',
max.nodes.per.row=20) # just node
PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19, highlight.nodes='Daphnia pulex', highlight.links=TrophicLinksForNodes(TL84, 'Daphnia pulex'), max.nodes.per.row=20) # node and trophic links
# ChesapeakeBay Data
data(ChesapeakeBay)
# plot basic food web
PlotWebByLevel(ChesapeakeBay,
col=1,
pch=20,
highlight.nodes=NULL)
# develop link line widths based on biomass flow
# log transform for graphical representation
link.lwd=log(ChesapeakeBay$trophic.links$biomass.flow)
# plot food web with link weights
PlotWebByLevel(ChesapeakeBay,
col=1,
pch=19,
highlight.nodes=NULL,
link.lwd=link.lwd,
main="Chesapeake Bay Weighted by Flow"
)
# custom symbols for each kingdom
symbol.spec = c(Bacteria=21, Plantae=22, Chromista=23,
Protozoa=24, Animalia=25, 19)
symbol.spec
## Bacteria Plantae Chromista Protozoa Animalia
## 21 22 23 24 25 19
colour.spec = c(Bacteria='purple3', Plantae='green3', Chromista='blue3', Protozoa='orange3',
Animalia='red3', 'black')
# Plot NvM and legend
PlotNvM(TL84,
symbol.by='kingdom', symbol.spec=symbol.spec, bg.by='kingdom', bg.spec=colour.spec, colour.by='kingdom', colour.spec=colour.spec, highlight.nodes=NULL)
legend("topright", legend=names(colour.spec), pch=symbol.spec,
col=colour.spec, pt.bg=colour.spec)
# different regression lines for desnity and biomass for diff kingdoms
PlotNvM(TL84,
symbol.by='kingdom', symbol.spec=symbol.spec, bg.by='kingdom', bg.spec=colour.spec, colour.by='kingdom', colour.spec=colour.spec, highlight.nodes=NULL, show.web=FALSE)
legend("topright", legend=names(colour.spec), pch=symbol.spec,
col=colour.spec, pt.bg=colour.spec)
models <- NvMLinearRegressions(TL84, class='kingdom')
colours <- PlotLinearModels(models, colour.spec=colour.spec)
# Lumping community by order
# Create vector desginating lumpage
lump <- NP(TL84, 'order') # NP extracts node/species property
head(lump, 20)
## Nostoc sp. Arthrodesmus sp.
## "Nostocales" "Desmidiales"
## Asterionella formosa Cryptomonas sp. 1
## "Fragilariales" "Cryptomonadales"
## Cryptomonas sp. 2 Chroococcus dispersus
## "Cryptomonadales" "Chroococcales"
## Closteriopsis longissimus Chrysosphaerella longispina
## "Chlorellales" "Chromulinales"
## Dinobryon bavaricum Dinobryon cylindricum
## "Chromulinales" "Chromulinales"
## Dactylococcopsis fascicularis Diceras sp.
## "Chroococcales" "Hibberdiales"
## Dictyosphaerium pulchellum Dinobryon sertularia
## "Chlorellales" "Chromulinales"
## Dinobryon sociale Glenodinium quadridens
## "Chromulinales" "Peridiniales"
## Microcystis aeruginosa Mallomonas sp. 1
## "Chroococcales" "Synurales"
## Mallomonas sp. 2 Unclassified flagellates
## "Synurales" ""
# rename parts of vector with "" for order name.
lump[""==lump] <- names(lump[""==lump] )
head(lump, 20)
## Nostoc sp. Arthrodesmus sp.
## "Nostocales" "Desmidiales"
## Asterionella formosa Cryptomonas sp. 1
## "Fragilariales" "Cryptomonadales"
## Cryptomonas sp. 2 Chroococcus dispersus
## "Cryptomonadales" "Chroococcales"
## Closteriopsis longissimus Chrysosphaerella longispina
## "Chlorellales" "Chromulinales"
## Dinobryon bavaricum Dinobryon cylindricum
## "Chromulinales" "Chromulinales"
## Dactylococcopsis fascicularis Diceras sp.
## "Chroococcales" "Hibberdiales"
## Dictyosphaerium pulchellum Dinobryon sertularia
## "Chlorellales" "Chromulinales"
## Dinobryon sociale Glenodinium quadridens
## "Chromulinales" "Peridiniales"
## Microcystis aeruginosa Mallomonas sp. 1
## "Chroococcales" "Synurales"
## Mallomonas sp. 2 Unclassified flagellates
## "Synurales" "Unclassified flagellates"
#create lumped community dataset
TL84.lumped <- LumpNodes(TL84, lump)
TL84.lumped
## Tuesday Lake sampled in 1984 (lumped) containing 22 nodes and 58 trophic links
# were gonna make 4 plots to NvM 1 not lumped and 1 lumped
par(mfrow=c(2,2))
PlotNvM(TL84, col=1, pch=19, highlight.nodes=NULL)
PlotNvM(TL84.lumped, col=1, pch=19, highlight.nodes=NULL)
PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19,
max.nodes.per.row=20)
PlotWebByLevel(TL84.lumped, y.layout='stagger', stagger=0.1,col=1, pch=19,
max.nodes.per.row=20)
# load dataset
data("pHWebs")
pHWebs
## A collection of 10 communities
# example communities (2/10)
pHWebs$`Old Lodge`
## Old Lodge containing 23 nodes and 137 trophic links
pHWebs$`Afon Hafren`
## Afon Hafren containing 25 nodes and 135 trophic links
pHWebs$`Afon Hafren`$properties
## $title
## [1] "Afon Hafren"
##
## $M.units
## [1] "mg"
##
## $N.units
## [1] "m^2"
##
## $code
## [1] "HAF"
##
## $pH
## [1] 5.3
##
## $lat
## [1] 52.47
##
## $long
## [1] -3.7
# Export pHWebs to a directory
SaveCollection(pHWebs, "./comm")
# Import pHWebs from a directory
pHWebs<-LoadCollection("./comm")
# Biomass by Abundance for multiple communities
plot(pHWebs, col=1, pch=19, highlight.nodes=NULL)
# Food Webs for multiple communities
plot(pHWebs, plot.fn=PlotWebByLevel, col=1, pch=19, highlight.nodes=NULL)
# Returns a data.frame of first-class and computed properties of communities (Master data frame)
CollectionCPS(pHWebs)
## title M.units N.units code pH lat long
## Afon Hafren Afon Hafren mg m^2 HAF 5.3 52.47 -3.700
## Allt a'Mharcaidh Allt a'Mharcaidh mg m^2 MHA 6.5 57.12 -3.850
## Bere Stream Bere Stream mg m^2 BER 7.5 50.73 -2.210
## Broadstone Broadstone mg m^2 BRO 5.5 51.08 0.053
## Dargall Lane Dargall Lane mg m^2 DAR 5.8 55.08 -4.430
## Duddon Pike Beck Duddon Pike Beck mg m^2 DUD1 6.1 54.41 -3.170
## Hardknott Gill Hardknott Gill mg m^2 DUD2 7.0 54.40 -3.170
## Mill Stream Mill Stream mg m^2 MIL 8.4 50.68 -2.180
## Mosedal Beck Mosedal Beck mg m^2 DUD3 5.9 54.41 -3.140
## Old Lodge Old Lodge mg m^2 OLD 5.0 51.04 0.080
# community characteristics
pH.char<-CollectionCPS(pHWebs, c('pH', #Community Property##i.e.: pHWebs$`Old Lodge`$properties
'NumberOfNodes', #cheddar function ##i.e.: NumberOfNodes(pHWebs$`Old Lodge`)
'NumberOfTrophicLinks', #cheddar function ##...
'DirectedConnectance', #cheddar function ##...
'NvMSlope')) #cheddar function ##...
head(pH.char)
## pH NumberOfNodes NumberOfTrophicLinks
## Afon Hafren 5.3 25 135
## Allt a'Mharcaidh 6.5 40 334
## Bere Stream 7.5 66 943
## Broadstone 5.5 25 178
## Dargall Lane 5.8 21 99
## Duddon Pike Beck 6.1 35 286
## DirectedConnectance NvMSlope
## Afon Hafren 0.2160000 -0.7078312
## Allt a'Mharcaidh 0.2087500 -0.7655290
## Bere Stream 0.2164830 -0.6501359
## Broadstone 0.2848000 -0.5853852
## Dargall Lane 0.2244898 -0.7379515
## Duddon Pike Beck 0.2334694 -0.5673022
# Node connectivity for all communities
pH.conn<-CollectionCPS(pHWebs, c('pH', #Community Property
'FractionBasalNodes', #cheddar function
'FractionIntermediateNodes',#cheddar function
'FractionTopLevelNodes', #cheddar function
'FractionIsolatedNodes')) #cheddar function
head(pH.conn)
## pH FractionBasalNodes FractionIntermediateNodes
## Afon Hafren 5.3 0.4000000 0.4800000
## Allt a'Mharcaidh 6.5 0.3500000 0.5250000
## Bere Stream 7.5 0.3939394 0.4393939
## Broadstone 5.5 0.3200000 0.6000000
## Dargall Lane 5.8 0.4285714 0.5238095
## Duddon Pike Beck 6.1 0.3714286 0.4857143
## FractionTopLevelNodes FractionIsolatedNodes
## Afon Hafren 0.12000000 0.00000000
## Allt a'Mharcaidh 0.12500000 0.00000000
## Bere Stream 0.15151515 0.01515152
## Broadstone 0.08000000 0.00000000
## Dargall Lane 0.04761905 0.00000000
## Duddon Pike Beck 0.14285714 0.00000000
# Plot relationships between pH and community structure.
par(mfrow=c(2,3))
with(pH.char, plot(pH, NumberOfTrophicLinks, pch=19, main="pH & NumberOfTrophicLinks", cex.lab=1.4))
with(pH.char, plot(pH, NumberOfNodes, pch=19, main="pH & NumberOfTrophicLinks", cex.lab=1.4))
with(pH.conn, plot(pH, FractionBasalNodes, pch=19, main="pH & FractionBasalNodes", cex.lab=1.4))
with(pH.conn, plot(pH, FractionIntermediateNodes, pch=19, main="pH & FractionIntermediateNodes", cex.lab=1.4))
with(pH.conn, plot(pH, FractionTopLevelNodes, pch=19, main="pH & FractionTopLevelNodes", cex.lab=1.4))
with(pH.conn, plot(pH, FractionIsolatedNodes, pch=19, main="pH & FractionIsolatedNodes", cex.lab=1.4))
# Order community by pH
pHWebs.d <- OrderCollection(pHWebs, 'pH', decreasing=TRUE)
# Plot food webs ordered by pH
plot(pHWebs.d, plot.fn=PlotWebByLevel, col=1, pch=19, highlight.nodes=NULL)